using UnityEngine;
using System.Collections;
using System;
using FM_Mono;

[IgnoreGen]
public class AndroidPermissionHandler : MonoBehaviour
{
    private static AndroidPermissionHandler _instance;
    
    [AcquireOnce]
    public static AndroidPermissionHandler instance
    {
        get
        {
            if(null == _instance)
            {
                GameObject go = GameObject.Find("PlatformFacade");
                _instance = go.AddComponent<AndroidPermissionHandler>();
            }

            return _instance;
        }
    }

    public event Action<bool, int> onRequestPermissionsCallback;

    private void OnRequestPermissionsSuccess(string requestCode)
    {
        Debug.Log("OnRequestPermissionsSuccess requestCode " + requestCode);

        if (null != onRequestPermissionsCallback)
        {
            onRequestPermissionsCallback(true, int.Parse(requestCode));
        }
    }

    private void OnRequestPermissionsFailed(string requestCode)
    {
        Debug.Log("OnRequestPermissionsFailed requestCode " + requestCode);
        if (null != onRequestPermissionsCallback)
        {
            onRequestPermissionsCallback(false, int.Parse(requestCode));
        }
    }

    private void OnDestroy()
    {
        onRequestPermissionsCallback = null;
    }
}